<template>
  <el-aside width="auto" height="auto">
    <el-menu :collapse="isCollapse" :default-active="onRoutes" background-color="#232323" text-color="#ccc" active-text-color="#ddd" unique-opened router>
      <template v-for="item in items">
        <template v-if="item.subItems">
          <el-submenu :index="item.path">
            <template slot="title">
              <i :class="item.icon"></i>
              <span slot="title">{{item.title}}</span>
            </template>
            <el-menu-item v-for="(subItem, i) in item.subItems" :index="subItem.path" :key="i">
              {{subItem.title}}
            </el-menu-item>
          </el-submenu>
        </template>
        <template v-else>
          <el-menu-item :index="item.path">
            <i :class="item.icon"></i>
            <span slot="title">{{item.title}}</span>
          </el-menu-item>
        </template>
      </template>
    </el-menu>
  </el-aside>
</template>

<script>
import Bus from "./bus";
export default {
  name: "Sidebar",
  data() {
    return {
      isCollapse: false,
      items: [
        {
          title: '账户安全',
          path: '/safety',
          icon: 'el-icon-setting'
        },
        {
          title: '我的参拍',
          path: '/participate',
          icon: 'el-icon-sell',
        },
        {
          title: '我的消息',
          path: '/message',
          icon: 'el-icon-user',
        },
        {
          title: '我的关注',
          path: '/concern',
          icon: 'el-icon-suitcase',
        },
        {
          title: '推荐标的',
          path: '/accountManage',
          icon: 'el-icon-office-building',
        },
        {
          title: '我的预约',
          path: '/subscribe',
          icon: 'el-icon-document',
        },
        {
          title: '拍卖会直播',
          path: '/live',
          icon: 'el-icon-takeaway-box',
        },
        {
          title: '我的发票信息',
          path: '/invoice',
          icon: 'el-icon-star-off',
        },
      ]
    }
  },
  computed: {
    onRoutes() {

      return this.$route.fullPath;
    }
  },
  created() {

    // 通过 event bus进行组件间的通信 来折叠和展开侧边栏
    Bus.$on('collapse', isCollapse => {

      this.isCollapse = isCollapse;
    });
  }
}
</script>

<style scoped lang="less">
  .el-menu {
  height: 100%;
  border: none;
  background-color: #225d86 !important;
&:not(.el-menu--collapse) {
   width: 200px;
 }
}
.el-menu-item.is-active {
  border-left: 3px solid #225d86;
  background-color:#030846 !important;
}
 .el-menu-item {
  border-left: 3px solid #225d86;
  background-color: #225d86 !important;
 }
</style>